﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace FBMCE
{
    public partial class TwitterLogin : Form
    {
        Twitter.TwitterAPI _twitterApi;

        public TwitterLogin(Twitter.TwitterAPI twitterApi)
        {
            _twitterApi = twitterApi;

            InitializeComponent();

            toolTip.SetToolTip(rememberMe, "Your username and password will NOT be stored anywhere, only access tokens generated by Twitter.");
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            btnLogin.Text = "Verifying...";

            btnLogin.Enabled = false;
            btnCancel.Enabled = false;
            userName.Enabled = false;
            password.Enabled = false;

            if (_twitterApi.Login(userName.Text, password.Text, rememberMe.Checked))
            {
                btnLogin.Text = "Done!";

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Twitter login failed, please check username and password!");

                btnLogin.Text = "Login";
                btnLogin.Enabled = true;
                btnCancel.Enabled = true;
                userName.Enabled = true;
                password.Enabled = true;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
